-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
48 lines (34 loc) · 1.05 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int B, N, D, C, V, j;
do {
B = sc.nextInt();
N = sc.nextInt();
if (B != 0 && N != 0) {
j = 0;
int[] Vx = new int[B + 1];
for (int i = 1; i <= B; i++)
Vx[i] = sc.nextInt();
for (int i = 0; i < N; i++) {
D = sc.nextInt();
C = sc.nextInt();
V = sc.nextInt();
Vx[D] -= V;
Vx[C] += V;
}
for (int i = 1; i <= B; i++) {
if (Vx[i] < 0)
j = 1;
}
if (j == 1)
System.out.println("N");
else
System.out.println("S");
}
} while (B != 0 && N != 0);
sc.close();
}
}